/**      
 * @file		swap.cpp
 * @description		This application demonstrates the conical swap 
 *			function. It shows what happens if we don't pass the
 *			variables by reference and what happens when we do
 * @course		CSCI 123 Section 00000
 * @assignment		Sample 5
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <string>
using namespace std;

/**
 * Swaps the values of variable 1 with variable 2
 * 
 * @param	var1 the value of variable 1
 * @param	var2 the value of variable 2
 * @pre		var1 and var2 have been initialized to values
 * @post	Due to the pass by value nature, variable 1 retains
 *		its value and variable 2 retains its initial value
 *		THIS FUNCTION HAS NO AFFECT ON THE VARIABLES
 */
void swapByValue(int aVar1, int aVar2);

/**
 * Swaps the values of variable 1 with variable 2
 * 
 * @param	var1 the value of variable 1
 * @param	var2 the value of variable 2
 * @pre		var1 and var2 have been initialized to values
 * @post	the value of variable 1 has been replaced with the value
 *		of variable 2 and the value of variable 2 has been replaced
 *		with the value of variable 1
 */
void swapByRef(int& aVar1, int& aVar2);

/**
 * This function outputs the values in var1 and var2
 * It is intended use is after one of the swap functions
 * have been called.
 * @param	funcName the name of the swap function that was called before 
 *		outputVars
 * @param	var1 the value of variable 1
 * @param	var2 the value of variable 2
 * @pre		variable 1 and 2 have been swapped by one of the swap functions
 * @post	The name of the swap function and the values of variables 1 and 2
 *		have been output to the user
 */
void outputVars(string aFuncName, int aVar1, int aVar2);

/**
 * @return zero if the application executes successfully
 */
int main() {
	int mVar1  = 5;
	int mVar2  = 8;
	cout << "Swapping mVar1 = 5 with mVar2 = 8\n";
	swapByValue(mVar1, mVar2);
	outputVars("swapByValue", mVar1, mVar2);
	swapByRef(mVar1, mVar2);
	outputVars("swapByRef", mVar1, mVar2);
	return 0;
}

void swapByValue(int aVar1, int aVar2) {
	int tempVar = aVar1; 	// save the value of var1 in tempVar
	aVar1 = aVar2;		// set var1 to var2's value
	aVar2 = tempVar;	// set var2 to the value of var1
}

void swapByRef(int& aVar1, int& aVar2) {
	int tempVar = aVar1; 	// save the value of var1 in tempVar
	aVar1 = aVar2;		// set var1 to var2's value
	aVar2 = tempVar;	// set var2 to the value of var1
}

void outputVars(string aFuncName, int aVar1, int aVar2) {
	cout << "mVar1 after " << aFuncName << " = " << aVar1 << endl;
	cout << "mVar2 after " << aFuncName << " = " << aVar2 << endl;
}
